/**
 * 给定汇率，问最后的钱数。直接计算就行
 */
#include <bits/stdc++.h>
using namespace std;

#include <bits/extc++.h>
using namespace __gnu_pbds;

using llt = long long;
using vi = vector<int>;
using pii = pair<int, int>;

int N;
vector<llt> A;
vector<pair<llt, llt>> P;

llt proc(){
    for(int i=1;i<N;++i){
        llt c = A[i] / P[i].first;
        A[i + 1] += c * P[i].second;
    }
    return A[N];
}

void work(){
    cin >> N;
    A.assign(N + 1, {});
    for(int i=1;i<=N;++i) cin >> A[i];
    P.assign(N, {});
    for(int i=1;i<N;++i) cin >> P[i].first >> P[i].second;
    cout << proc() << endl;
    return;
}

int main(){
#ifndef ONLINE_JUDGE
    freopen("z.txt", "r", stdin);
#endif
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int nofkase = 1;
    // cin >> nofkase;
    while(nofkase--) work();
    return 0;
}